home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 04 / mscbugs / msc5bug4.c < prev   
C/C++ Source or Header  |  1987-12-15  |  712b  |  26 lines

  1. /* TEST APPENDING TEXT TO A FILE TERMINATED WITH CTRL-Z */
  2. /* WORKS CORRECTLY UNDER VERSION 4 BUT FAILS UNDER VERSION 5 */
  3. #include <assert.h>
  4. #include <io.h>
  5. #include <memory.h>
  6. #include <process.h>
  7. #include <stdio.h>
  8. main()
  9. {
  10.     static char old[] = { 'x', 'y' }, new[sizeof(old)];
  11.     FILE *fp; static char nam[] = "XXXXXX";
  12.     mktemp( nam );
  13.     fp = fopen( nam, "wb" );
  14.     fwrite( old, 1, 1, fp );
  15.     fputc( '\x1A', fp );            /* old-style end-of-file */
  16.     fclose( fp );
  17.     fp = fopen( nam, "at" );
  18.     fwrite( old+1, sizeof(old)-1, 1, fp );
  19.     fclose( fp );
  20.     fp = fopen( nam, "rt" );
  21.     fread( new, sizeof(new), 1, fp );
  22.     fclose( fp );
  23.     assert( ! memcmp( old, new, sizeof( old ) ) );
  24.     return remove( nam );
  25. }
  26.